﻿using Microsoft.VisualStudio.SharePoint;
using Microsoft.VisualStudio.SharePoint.Deployment;
using System.ComponentModel.Composition;

namespace SPVSX.DeploymentExtensions.DeploymentConfigurations
{
    // Enables Visual Studio to discover and load this project-level extension.
    [Export(typeof(ISharePointProjectExtension))]

    /// <summary>
    /// TODO: Comment
    /// 
    /// This code is a WIP and is in need of improved commenting, exception handling, and potentially
    /// factoring.  Please be nice.
    /// 
    /// Though this code is Open Source, in good faith it is requested that you consult the original author(s)
    /// before changing or re-using it for any public endeavour intended to provide similar functionality, or
    /// to fix simple bugs.  In other words, if you want to create SPVSX2, please let us know first.
    /// </summary>
    /// <remarks>@author Matt Smith, http://blog.mattsmith.co.nz</remarks>  
    internal class QuickDeployAssembliesDeploymentConfigurationExtension : ISharePointProjectExtension
    {
        // Implements ISharePointProjectExtension.Initialize.
        public void Initialize(ISharePointProjectService projectService)
        {
            projectService.ProjectInitialized += ProjectInitialized;            
        }

        // Creates the new deployment configuration.
        private void ProjectInitialized(object sender, SharePointProjectEventArgs e)
        {
            if (!e.Project.DeploymentConfigurations.ContainsKey("Quick Deploy (GAC/BIN Only)"))
            {
                string[] deploymentSteps = new string[] 
                {
                    DeploymentStepIds.RecycleApplicationPool,
                    "SPVSX.DeploymentSteps.CopyBinaries"
                };

                string[] retractionSteps = new string[] 
                {
                };

                IDeploymentConfiguration configuration = e.Project.DeploymentConfigurations.Add(
                    "Quick Deploy (GAC/BIN Only)", deploymentSteps, retractionSteps);
                configuration.Description = "This is the Quick Deploy (GAC/BIN Only) deployment configuration";
            }
        }
    }
}